﻿using AutoMapper;

namespace GroceryPriceBook.Core.Mappers
{
	/// <summary>
	/// View Model object for presentation which inherits the AutoMapper Profile class
	/// </summary>
	public class PurchaseLogItem : Profile
	{
		public override string ProfileName
		{
			get { return "PurchaseLogItemMappings"; }
		}

		protected override void Configure()
		{
			Mapper.CreateMap<Model.PurchaseLogItem, ViewModel.PurchaseLogItem>()
				  .ForMember(dest => dest.ProductId, opt => opt.MapFrom(src => src.Product))
				  .ForMember(dest => dest.Product, opt => opt.MapFrom(src => src.Product1));
			Mapper.CreateMap<ViewModel.PurchaseLogItem, Model.PurchaseLogItem>()
				  .ForMember(dest => dest.Product, opt => opt.MapFrom(src => src.ProductId))
				  .ForSourceMember(src => src.Product, opt => opt.Ignore())
				  .ForSourceMember(src => src.ProductSelectListItems, opt => opt.Ignore());
		}
	}
}
